/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * dlgResultados.java
 *
 * Created on 23/05/2010, 01:32:43 PM
 */

package GUI.Evaluacion;
import BusinessEntity.Evaluacion.*;
import BusinessLogic.Evaluacion.*;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;
import net.sf.jasperreports.swing.JRViewer;
import net.sf.jasperreports.engine.JasperPrint;

/**
 *
 * @author Jose Miguel
 */
public class dlgResultados extends javax.swing.JDialog {
    ArrayList<ResultadoAnalisisBE> listaAnalisis;
    DefaultTableModel objModelo;

    /** Creates new form dlgResultados */
    public dlgResultados(java.awt.Frame parent, boolean modal, ArrayList<ResultadoAnalisisBE> listaAnalisis) {
        super(parent, modal);
        this.listaAnalisis = listaAnalisis;
        actualizarGrillaResultado();
        initComponents();
    }
    
    public dlgResultados(java.awt.Frame parent, boolean modal){
        super(parent, modal);        
        initComponents();        
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        pnlPlagio = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        grlResultado = new javax.swing.JTable();
        btnReporte = new javax.swing.JButton();
        btnVerOriginales = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Resultado de Análisis");
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 16));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Resultados de Análisis");
        jLabel1.setIconTextGap(5);
        jLabel1.setName("lblRptPlagiados"); // NOI18N
        jLabel1.setPreferredSize(new java.awt.Dimension(106, 30));

        pnlPlagio.setBorder(javax.swing.BorderFactory.createTitledBorder("Fin de Análisis"));

        grlResultado.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2, true));
        grlResultado.setModel(objModelo);
        grlResultado.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(grlResultado);

        btnReporte.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Detalle.png"))); // NOI18N
        btnReporte.setText("Reporte");
        btnReporte.setMaximumSize(new java.awt.Dimension(125, 41));
        btnReporte.setMinimumSize(new java.awt.Dimension(125, 41));
        btnReporte.setName("btnVerDetalle"); // NOI18N
        btnReporte.setPreferredSize(new java.awt.Dimension(141, 41));
        btnReporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReporteActionPerformed(evt);
            }
        });

        btnVerOriginales.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Comparacion.png"))); // NOI18N
        btnVerOriginales.setText("Ver Originales");
        btnVerOriginales.setMaximumSize(new java.awt.Dimension(133, 41));
        btnVerOriginales.setMinimumSize(new java.awt.Dimension(133, 41));
        btnVerOriginales.setPreferredSize(new java.awt.Dimension(141, 41));
        btnVerOriginales.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVerOriginalesActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlPlagioLayout = new javax.swing.GroupLayout(pnlPlagio);
        pnlPlagio.setLayout(pnlPlagioLayout);
        pnlPlagioLayout.setHorizontalGroup(
            pnlPlagioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPlagioLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlPlagioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlPlagioLayout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlPlagioLayout.createSequentialGroup()
                        .addComponent(btnReporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(72, 72, 72)
                        .addComponent(btnVerOriginales, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(69, 69, 69))))
        );
        pnlPlagioLayout.setVerticalGroup(
            pnlPlagioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlPlagioLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(pnlPlagioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnVerOriginales, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnReporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(140, 140, 140)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(pnlPlagio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(pnlPlagio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public void actualizarGrillaResultado(){
        objModelo = new DefaultTableModel(){
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;  //El resto de celdas no son editables.
            }
        };
        objModelo.addColumn("Documento");
        objModelo.addColumn("Resultado");
        objModelo.addColumn("Porcentaje de Plagio");
        for(int i=0;i<this.listaAnalisis.size();i++){
            objModelo.addRow(new Object[]{  this.listaAnalisis.get(i).getNombreDocumentoSospechoso(),
                                            this.listaAnalisis.get(i).getResultadoPlagio(),
                                            this.listaAnalisis.get(i).getPorcentajeTotal()
            });
        }

    }

    private void btnReporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReporteActionPerformed
        // TODO add your handling code here:
        HashMap parametros = new HashMap();
        parametros.put("Logo", ".//src//Imagenes//BuscarComputadora.png");
        parametros.put("Titulo", "Resultado de Análisis");
        parametros.put("Subtitulo", "Documentos");
        JasperPrint jprint = EvaluacionBL.generaReporte("rptReporteAnalisis", parametros, null);

        try {
            JRViewer jrv = new JRViewer(jprint);
            JFrame frmReporteAnalisis = new JFrame();
            frmReporteAnalisis.getContentPane().add(jrv,BorderLayout.CENTER);
            frmReporteAnalisis.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            frmReporteAnalisis.setSize(706, 478);

            frmReporteAnalisis.setTitle("Pre - View de Resultado de Análisis");
            frmReporteAnalisis.setVisible(true);

        }catch(Exception e){
            System.out.println(e.getMessage());
        }

    }//GEN-LAST:event_btnReporteActionPerformed

    private void btnVerOriginalesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVerOriginalesActionPerformed
        // TODO add your handling code here:
        int seleccion = this.grlResultado.getSelectedRow();
        ResultadoAnalisisBE res;
        if (seleccion!=-1){
            res = this.listaAnalisis.get(seleccion);
        }else{
            res = null;
            return;
        }

        new dlgFuentes(this, true, res).setVisible(true);
}//GEN-LAST:event_btnVerOriginalesActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                dlgResultados dialog = new dlgResultados(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnReporte;
    private javax.swing.JButton btnVerOriginales;
    private javax.swing.JTable grlResultado;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel pnlPlagio;
    // End of variables declaration//GEN-END:variables

}
